package com.hbnu.system.controller;

import com.hbnu.system.core.base.Rest;
import com.hbnu.system.model.entity.Projectcate;
import com.hbnu.system.service.ProjectCateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Projectcate")
@Api(tags = "纵向-项目类别模块")
public class ProjectCateController {
    @Autowired
    private ProjectCateService projectCateService;

    @ApiOperation("项目类别添加")
    @PostMapping("/addProjectcate")
    public Rest<Boolean> addProjectcate(@RequestBody Projectcate projectcate){
        boolean add = projectCateService.addProjectCate(projectcate);
        return add ? Rest.success():Rest.failed();
    }

    @ApiOperation("获取项目类别列表")
    @GetMapping("/getProjectCate")
    public Rest<List<Projectcate>> getProjectcates(){
        List<Projectcate> projectcateList = projectCateService.getProjectCateList();
        return Rest.success(projectcateList);
    }

    @ApiOperation("项目类别-修改")
    @PostMapping("/updateProjectcate")
    public Rest<Boolean> updateProjectcate(@RequestBody Projectcate projectcate){
        boolean update = projectCateService.updateProjectCate(projectcate);
        return update ? Rest.success() : Rest.failed();
    }

    @ApiOperation("项目类别-删除")
    @GetMapping("/deleteProjectcate")
    public Rest<Boolean> deleteProjectcate(String projectcateID){
        boolean delete = projectCateService.deleteProjectCate(projectcateID);
        return delete ? Rest.success() : Rest.failed();
    }

    @ApiOperation("项目类别-根据名字查询")
    @GetMapping("/getProjectCateByName")
    public Rest<List<Projectcate>> getProjectCateByName(String projectcateName){
        List<Projectcate> projectcateList = projectCateService.getByProjectCateName(projectcateName);
        return Rest.success(projectcateList);
    }
}
